<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script
      type="text/javascript"
      src="https://api.map.baidu.com/api?type=webgl&v=1.0&ak=CPxHyHH5XD8mUnmRPbv9BehycOEklp34"
    ></script>
    <title>轨迹</title>
    <style>
      body,
      html,
      #allmap {
        width: 100%;
        height: 100%;
        overflow: hidden;
        margin: 0;
        font-family: "微软雅黑";
      }
    </style>
  </head>
  <body>
    <div id="allmap"></div>
  </body>
</html>
<script>
  const bmap = new BMapGL.Map("allmap"); // 创建地图实例
  const point = new BMapGL.Point(116.404, 39.915); // 创建点坐标
  bmap.centerAndZoom(point, 12); // 设置中心点坐标和地图级别
  bmap.enableScrollWheelZoom(); // 开启鼠标滚轮缩放

  // 绘制线段
  // Polygon 三角形
  // Polyline 线段

  const polyline = new BMapGL.Polygon(
    [
      new BMapGL.Point(116.8, 39.8), // 起点
      new BMapGL.Point(117.0, 39.82), // 中间点
      new BMapGL.Point(117.2, 40.8), // 终点
      new BMapGL.Point(116.8, 39.8), // 闭合
    ],
    {
      strokeColor: "blue", // 线色
      strokeWeight: 4, // 线宽
      strokeOpacity: 0.5, // 透明度
      fillColor: "blue", // 填充颜色
    }
  );
  bmap.addOverlay(polyline);
</script>
